package cn.pegasus.teamwork.pegasus.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.iyizhan.teamwork.base.util.PageObject;
import cn.iyizhan.teamwork.base.util.ParameterEunm;
import cn.iyizhan.teamwork.base.util.ReMessage;
import cn.pegasus.teamwork.manager.controller.BaseManagerController;
import cn.pegasus.teamwork.pegasus.entity.BussUcenterArea;
import cn.pegasus.teamwork.pegasus.entity.BussUserComment;
import cn.pegasus.teamwork.pegasus.mapper.BussUserCommentMapper;
import cn.pegasus.teamwork.pegasus.service.BussUserCommentService;

/**
 * 评论
 * @author 40854
 *
 */
@Controller
@RequestMapping("/comment")
public class CommentController extends BaseManagerController<BussUserComment, BussUserCommentMapper>{
	
	private static final Logger logger = LoggerFactory.getLogger(CommentController.class);
	
	@Autowired
	private BussUserCommentService userCommentService;
	/**
	  * 查询评论列表
	  */
	 @RequestMapping(value = "/list",method = {RequestMethod.GET})
	 public ModelAndView list(@RequestParam Map<String, Object> map){
		 ModelAndView view = new ModelAndView("comment/comment-list");
		 if(map.isEmpty()){
			map.put("pageData", 10);
			map.put("curPage", 1);
		}
		 try{
			 PageObject<BussUserComment> dicList = userCommentService.PageList(map);
			 view.addObject("list", dicList);
			 view.addObject("map", map);
		 }catch(Exception e){
			 logger.error("查询评论列表异常",e.getMessage());
		 }
		 return view;
	 }
	 /**
	  * 跳转评论页面
	  */
	 @RequestMapping(value="/goAdd" ,method = {RequestMethod.GET})
	 public ModelAndView goAddArea(@RequestParam(value="id",required = false) String id){
		 ModelAndView view = new ModelAndView("comment/comment-edit");
		 view.addObject("id", id);
		 return view;
	 }
	 /**
	  * 回复
	  */
	 @ResponseBody
	 @RequestMapping(value = "/addComment")
	 public String addComment(@RequestParam(value="id",required = false) String id,
			 @RequestParam(value="descs",required = false) String descs){
        try {
        	userCommentService.addComment(getAdmin().getId(), id,descs);
        } catch (Exception e) {
            logger.error("回复评论异常", e);
            return "1001";
        }
        return "200";
	 }
	 /**
	  * 查看评论详情
	  */
	 @RequestMapping(value="/findComment")
	 public ModelAndView findComment(@RequestParam(value="id",required = false) Long id){
		 ModelAndView view = new ModelAndView("comment/comment-info");
		 List<BussUserComment> list = userCommentService.findComment(id);
		 view.addObject("list", list);
		 return view;
	 }
}
